<template>
  <div class="container">
    <div class="select-container">
      <el-input
        size="small"
        style="width: 200px;"
        class="filter-item"
        placeholder="输入接口描述"
        clearable
        v-model="interfaceDesc"
        prefix-icon="el-icon-search">
      </el-input>
      <el-button size="small" type="success" @click="fetchData()" style="margin-right: 10px">查 询</el-button>
    </div>
    <div class="list-container">
      <div class="filter">
        <el-row :gutter="20">
          <el-col :span="10">
            <span style="line-height: 33px;padding-left:10px;">接口信息管理</span>
          </el-col>
          <el-col :span="14" style="text-align: right;">
            <el-button size="small" type="primary" @click="createClick()" style="margin-right: 10px">创建业务接口</el-button>
          </el-col>
        </el-row>
      </div>
      <div class="data-contant">
        <div>
          <el-table
            :key='tableKey'
            :data="list.records"
            v-loading="listLoading"
            element-loading-text="给我一点时间"
            size="small"
            stripe
            style="width: 100%;border:#eeeeee"
            highlight-current-row>
            <el-table-column
              align="center"
              type="index"
              width="80"
              label="编号">
            </el-table-column>
            <el-table-column
              align="center"
              label="接口描述"
              prop="interfaceDescription">
            </el-table-column>
            <el-table-column
              align="center"
              label="接口用途"
              prop="interfaceUse">
            </el-table-column>
            <el-table-column
              align="center"
              label="接口状态"
              prop="isDisable">
            </el-table-column>
            <el-table-column
              align="center"
              label="所属业务系统"
              prop="belongSystem">
            </el-table-column>
            <el-table-column
              align="center"
              label="接口类型"
              prop="interfaceType">
            </el-table-column>
            <el-table-column align="center" label="操 作" width="290px" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
                <el-button type="primary" size="small" @click="handleDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination
              layout=" total, prev, pager, next"
              :page-size = "this.postList.rowBounds.limit"
              :total="this.list.count"
              @current-change="current_change">
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!--接口管理弹出层-->
    <el-dialog
      v-if="dialogVisibleEditSysCode"
      :close-on-click-modal="false"
      title="编辑接口"
      :visible.sync="dialogVisibleEditSysCode"
      width="70%">
      <interface-info-update :listId="listId" @changeCloseDialog="changeCloseDialog"></interface-info-update>
    </el-dialog>
    <!--接口管理弹出层-->
    <el-dialog
      v-if="dialogVisibleEditSysCodeAdd"
      :close-on-click-modal="false"
      title="编辑接口"
      :visible.sync="dialogVisibleEditSysCodeAdd"
      width="70%">
      <interface-info-add @changeCloseAddDialog="changeCloseAddDialog"></interface-info-add>
    </el-dialog>
  </div>
</template>

<script>
import '@/styles/newstyle.scss'
import {
  interfaceInfoSelect,
  interfaceInfoDelete
} from '@/api/bussSystemManage/interfaceInfo'
import interfaceInfoUpdate from './interfaceInfoUpdate'
import interfaceInfoAdd from './interfaceInfoAdd'
export default {
  components: {
    interfaceInfoUpdate,
    interfaceInfoAdd
  },
  data() {
    return {
      listId: {},
      dialogVisibleEditSysCodeAdd: false,
      dialogVisibleEditSysCode: false,
      tableKey: 0,
      interfaceDesc: '',
      list: {},
      postList: {
        condition: [{
          'property': 'isDisable',
          'value': '2',
          'type': 'NE'
        }],
        sort: [{
          direction: 'DESC',
          property: 'createTime'
        }],
        rowBounds: {
          offset: 0,
          limit: 10
        }
      },
      listLoading: false,
      deletelist: {},
      getIsDisable: [
        {
          label: '0',
          value: '正常'
        },
        {
          label: '1',
          value: '禁用'
        }
      ]
    }
  },
  // 画面刚进入method
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.loading = true
      /*
      var con = this.getUser()
       if(con.length==1){
         this.postList.condition.push(con[0])
       }
      */
      this.postList.condition.forEach(function(item, index, arr) {
        if (item.property == 'interfaceDescription') {
          arr.splice(index, 1)
        }
      })
      if (this.interfaceDesc!='') {
        this.postList.condition.push({
          'property': 'interfaceDescription',
          'value': this.interfaceDesc,
          'type': 'LIKE'
        })
      }
      interfaceInfoSelect(this.postList).then(res => {
        this.list = res.data.data
        this.list.records = res.data.data.records
        this.list.records.forEach((item, i) => {
          this.getIsDisable.forEach((newgetIsDisable, orggetIsDisable) => {
            if (item.isDisable === newgetIsDisable.label) {
              item.isDisable = newgetIsDisable.value
            }
          })
        })
        this.loading = false
      }).catch((err) => {
        console.log(err)
      })
    },
    formatDate(datestr) {
      var year = datestr.slice(0, 4)
      var month = datestr.slice(4, 6)
      var date = datestr.slice(6, 8)
      return year + '-' + month + '-' + date
    },
    deleteData() {
      interfaceInfoDelete(this.deletelist).then(res => {
        this.fetchData()
      }).catch((err) => {
        console.log(err)
      })
    },
    handleDelete(row) {
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deletelist.interfaceInfoId = row.interfaceInfoId
        this.deleteData()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    createClick() {
      this.dialogVisibleEditSysCodeAdd = true
    },
    changeCloseAddDialog() {
      this.dialogVisibleEditSysCodeAdd = false
    },
    handleEdit(row) {
      this.listId = row
      this.dialogVisibleEditSysCode = true
    },
    changeCloseDialog() {
      this.dialogVisibleEditSysCode = false
    },
    current_change(currentPage) { // 通过分页获取数据
      const page = currentPage - 1
      this.postList.rowBounds.offset = page * 10
      this.fetchData()
    }
  }
}
</script>

<style scoped>
  .container{
    color: #3b96f3;
    background: #fff;
    padding: 20px;
    height: 100%;
    overflow-y: auto;
  }
  .select-container{
    padding: 10px 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    border: 1px solid #eeeeee;
  }
  .list-container{
    margin-top:30px;
    padding:0 10px 10px 10px;
    border:1px solid#eeeeee;
    border-radius: 4px;
  }
  .data-contant{
    background-color: rgba(0,0,0,.035);
    padding: 30px 10px 20px;
  }
  .data-detail{
    font-size: 14px;
    padding:20px 0;
    text-align: center;
  }
  .data-title{
    font-size: 14px;
    padding:10px 0;
    text-align: center;
  }
  .data-title div{
    font-size: 14px;
    padding:5px 0;
  }
  .filter{
    padding: 10px 5px;
    border-bottom: 2px solid#eeeeee;
  }
  .list-container{
  }
  .bold{
    font-weight: bold;
  }
</style>
